package org.example.Demo;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.example.pojo.Brand;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class JDBC_Test01 {
    public static void main(String[] args) throws Exception {
        //加载配置文件
        Properties prop = new Properties();
        prop.load(new FileInputStream("D:\\JavaCode\\JDBC_Demo1\\jdbcDemo\\druid.properties"));

        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        //获取数据库连接
        Connection conn = dataSource.getConnection();


        //int status = 1;
        String sql = "select * from tb_brand";
        PreparedStatement prpstetm = conn.prepareStatement(sql);
        //prpstetm.setInt(1,status);
        ResultSet res = prpstetm.executeQuery();



        /*List<Brand> arr = new ArrayList<>();
        //查询的结果
        while (res.next()){
            Brand brand = new Brand();
            int id = res.getInt(1);
            String brandName = res.getString(2);
            String companyName = res.getString(3);
            int ordered = res.getInt(4);
            String description = res.getString(5);
            int temp_status = res.getInt(6);
            //构建brand对象
            brand.setId(id);
            brand.setBrandName(brandName);
            brand.setCompanyName(companyName);
            brand.setOrdered(ordered);
            brand.setDescription(description);
            brand.setStatus(temp_status);
            //把构建好的对象添加到list集合中
            arr.add(brand);
        }
        for (Brand brand : arr) {
            System.out.println(brand);
        }*/

    }
}
